#ifndef DAEMONPROXY_H
#define DAEMONPROXY_H

#include <QObject>
#include <QLocalServer>
#include <QLocalSocket>
class DaemonProxy : public QObject
{
    Q_OBJECT
public:
    enum class SocketObj{
        SO_Unkown = 0,
        
        SO_Check = 1,
        SO_Autoupdate,
        SO_OSUpgrade,
        SO_DoUpgradeSig,
        SO_Tipstop,
        SO_Tipstart,
        SO_Shutdown,
        SO_reboot,
        SO_Register,
        SO_Wallpaper,
        SO_EsportBox
    };
    Q_ENUM(DaemonProxy::SocketObj)
    
    enum class ProcessObj{
        PO_PersonCenter,
        PO_Upgrade,
        PO_SDDM,
        PO_EsportBox
    };
    Q_ENUM(DaemonProxy::ProcessObj)
    explicit DaemonProxy(QObject *parent = nullptr);
    
    bool socketServer();
    
    QString   getKeyword(SocketObj);
    SocketObj getEnumValue(QString);
    
    bool autoUpgrade() const;
    void setAutoUpgrade(bool newAutoUpgrade);

    bool reboot() const;
    
    bool shutdown() const;
    bool userCheck() const;
    
    bool errorReShut() const;
    
private:
    QLocalServer* m_localServer = nullptr;
    
    QMap<SocketObj,QString> m_keywordMap;
    QMap<ProcessObj,QLocalSocket*> m_commMap;
    bool m_autoUpgrade = false;
    bool m_userCheck = false;
    
    bool m_reboot = false;
    bool m_shutdown = false;
    bool m_errorReShut = false;
private:
    void initMap();
    
private slots:
    void onNewConnction();
    void onReadyRead();
public slots:
    void onSendMsg(ProcessObj,QString);
    void onDisconnectAllClient();
signals:
    void sigPostOtaFirmwareGet();
    void sigReadTaskFile();
    void sigDoUpgrade();
    void sigTipStatus(int);         // 提醒升级开关 0开 2关
    void sigSDDMRegister();
    void sigReadWallpaper(QString user);
    void sigPower();
};

#endif // DAEMONPROXY_H
/* 
 * 使用QLocalSocket方式的进程通讯类，服务端;
 * 保存接收数据变量，发送信号给业务类处理
*/
